package me.leiusual.sharing.widget

import android.content.Context
import android.graphics.Canvas
import android.graphics.Path
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatImageView

/**
 * Create by leiusual on 2018/7/17
 */
class CircleImageView @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : AppCompatImageView(context, attrs, defStyleAttr) {

  private val path = Path()

  override fun onDraw(canvas: Canvas) {
    val width = measuredWidth.toFloat()
    val height = measuredHeight.toFloat()
    path.apply {
      rewind()
      addCircle(width / 2, height / 2, width / 2, Path.Direction.CW)
    }
    canvas.clipPath(path)
    super.onDraw(canvas)
  }
}